package com.ruoyi.hxf.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.hxf.domain.Comment;
import com.ruoyi.hxf.domain.Topic;
import com.ruoyi.hxf.mapper.CommentMapper;
import com.ruoyi.hxf.mapper.EducationMapper;
import com.ruoyi.hxf.service.ICommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 评论管理 服务层实现
 *
 * @author hxf
 */
@RequiredArgsConstructor
@Service
public class CommentServiceImpl implements ICommentService {
    private final CommentMapper baseMapper;
    private QueryWrapper<Comment> wrapper;
    @Override
    public TableDataInfo<Comment> selectPageCommentList(Comment comment, PageQuery pageQuery) {
        Page<Comment> page = baseMapper.selectPageAndUser(pageQuery.build(), this.buildQueryWrapper(comment));
        return TableDataInfo.build(page);
    }


    private Wrapper<Comment> buildQueryWrapper(Comment comment) {
        wrapper = Wrappers.query();
        wrapper.eq("ft.is_delete", 0)
            .eq("ft.topic_id",comment.getTopicId())
            .last("order by create_time desc");
        return wrapper;
    }

    @Override
    public int insertComment(Comment comment) {
        return baseMapper.insert(comment);
    }

    @Override
    public Comment select(Comment comment) {
        return baseMapper.select(comment);
    }

    @Override
    public boolean selectCommentLike(String commentId, String userId, String type) {
        return baseMapper.selectCommentLike(commentId,userId,type);
    }

    @Override
    public void updateCommentLike(String commentId, String userId, String status, String type) {
        baseMapper.updateCommentLike(commentId,userId,status,type);
    }

    @Override
    public void insertCommentLike(String commentId, String userId, String status, String type) {
        baseMapper.insertCommentLike(commentId,userId,status,type);
    }

    @Override
    public String selectCollectionByUserIdAndCommentId(Long userId, Long commentId, String type) {
        return baseMapper.selectCollectionByUserIdAndCommentId(userId,commentId,type);
    }

    @Override
    public Comment queryById(String commentId) {
        return baseMapper.selectById(commentId);
    }

    @Override
    public int updateByComment(Comment comment) {
        return baseMapper.updateById(comment);
    }
}
